Skip to content

Could not parse CSS stylesheet - Reappears in 11.10.0 for certain stylesheets #2230

Closed
@techiev2

Description

Basic info:

  • Node.js version: 9.10.1
  • jsdom version: 11.10.0

@domenic thanks for taking this issue up in earlier commits. I read through the other related issues/replies and the issue #2132 referenced in #2177. I'm on 11.1.0 right now and seem to have the issue as well.

Tried reading through the source to figure where the issue might be cropping up from. Wasn't able to progress much to ascertain the root of the issue so creating an issue with the minimal stack trace and the helpers I've used in my local environment.

Minimal reproduction case

const { JSDOM } = require("jsdom");
const http = require('http');
const https = require('https');

function getPageHtml(url) {

    let getter = url.indexOf('https') === 0 ? https.get : http.get;

    return new Promise(function (resolve, reject) {
        let contents = '';

        try {
            getter(url, (res) => {
                res.on('data', (chunk) => {
                    contents += chunk;
                });
                res.on('end', () => {
                    let status = res.statusCode
                    if (status === 200) {
                        resolve(contents);
                    } else {
                        reject({ error: true });
                    }
                });
                res.on('error', (err) => {
                    reject({ error: true });
                });
            });
        } catch (err) {
            reject({ error: true });
        }
    });
}

const options = { resources:'usable' };
const url = 'https://www.thehindubusinessline.com/money-and-banking/rbi-alone-cannot-take-decision-on-virtual-currencies/article23884315.ece';

/* The helper that I use to generate a JSDOM document from page HTML */
function getDocument(html) {
    const { JSDOM } = jsdom;
    const jsDOMOptions = { resources: 'usable' };
    return new JSDOM(html, jsDOMOptions).window.document;
}

/* Trace back from the helper, arising out of Object.exports.createStyleSheet */

at Object.exports.createStylesheet (/home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/living/helpers/stylesheets.js:35:21)
    at HTMLLinkElementImpl.resourceLoader.load.data (/home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/living/helpers/stylesheets.js:70:13)
    at /home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/browser/resource-loader.js:31:22
    at Object.check (/home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:75:11)
    at Object.check (/home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:78:23)
    at Object.check (/home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:78:23)
    at Object.check (/home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:78:23)
    at Object.check (/home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:78:23)
    at /home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:94:12
    at wrappedEnqueued (/home/smv/Desktop/pdoc/node_modules/jsdom/lib/jsdom/browser/resource-loader.js:253:16) @font-face{font-family:'Conv_Lato-Bold';src:url('../fonts/Lato-Bold.eot');src:local('☺'),url('../f`

How does similar code behave in browsers?

I haven't tried this in JSBin since I couldn't get jsdom as a dependency there. I'll try an alternative environment and update the issue if that would help.

Activity

domenic

domenic commented on May 16, 2018

@domenic
Member

It seems likely that this website is using CSS features that we cannot parse, which in our current architecture, causes us to throw away the entire stylesheet and warn you that we've done so. So this is working as intended, modulo our poor CSS support.

techiev2

techiev2 commented on Feb 25, 2019

@techiev2
Author

Thanks for that @domenic. The primary issue was with the console error seeping to my Python subsystem's error pipe and not the parsing itself.

I've since added a virtualConsole to the DOM tree and a no-op handler to it to skip the issue from seeping out to the error IO pipe.

Fwiw, in case anyone else is looking at a similar issue in the future, the below flow skips the CSS/JS errors from seeping out.

const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const virtualConsole = new jsdom.VirtualConsole();
virtualConsole.on("error", () => {
  // No-op to skip console errors.
});
const dom = new JSDOM(``, { virtualConsole });

I'm closing this issue since it is resolved with the above change to my flow. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @techiev2@domenic@Zirro

      Issue actions

        Could not parse CSS stylesheet - Reappears in 11.10.0 for certain stylesheets · Issue #2230 · jsdom/jsdom